package xml;

import org.dom4j.Attribute;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

/**
 * @Author wangzhipeng
 * @Date 2020-08-25 9:23 下午
 * @Description
 */
public class ServerParser {
    public static void main(String[] args) throws DocumentException {
        //创建解析器
        SAXReader saxReader = new SAXReader();
        //通过解析器的read方法将配置文件读取到内存中
        Document document = saxReader.read("src/main/java/xml/server");
        //获取connector节点元素对象的xpath路径   /server/service/connector       servet//connector  //connector
        Element connectorElt = (Element) document.selectSingleNode("//connector");

        //第一种
        Attribute portAttr = connectorElt.attribute("port");
        String port = portAttr.getStringValue();
        System.out.println(port);
        //第二种
        String port1 = connectorElt.attributeValue("port");
        System.out.println(port1);
    }
}
